<?php

class Post_IndexController extends Zend_Controller_Action
{
	protected $_hostClassIdName = NULL;
	protected $_hostId = 0;
	protected $_hostObj = NULL;

	protected $_classIdName = NULL;
	protected $_classContainer = NULL;
	protected $_classItem = NULL;

	protected $_pathInfo = NULL;


	public function init()
	{
		parent::init();


		$this->_hostClassIdName = $this->_getParam('post_host_class');
		$this->_hostId = intval($this->_getParam('post_host_id'));

		if (empty($this->_hostClassIdName) || $this->_hostId < 1) {
			$this->_hostClassIdName = $this->_getParam('entity_class');
			$this->_hostId = intval($this->_getParam('entity_id'));
		}

		if (empty($this->_hostClassIdName) === FALSE && $this->_hostId > 0) {
			$this->_hostObj = Euso_Object::getInstance($this->_hostClassIdName, $this->_hostId);
		}


		$this->_pathInfo = $this->_getParam('dashboard_path_info');


		$postClass = $this->_getParam('post_class');
		if (empty($postClass)) {
			$postClass = $this->_getParam('dashboard_page_name');
			if (empty($postClass)) {
				throw new Zend_Controller_Action_Exception('Unexpected route', 500);
			}
		}
		// Remove the namespace (if any)
		$classPaths = explode('.', $postClass);
		$n = count($classPaths);
		$this->_classIdName = $classPaths[$n - 1];
		if (empty($this->_classIdName)) {
			throw new Zend_Controller_Action_Exception('Unexpected post class ['.__LINE__.']', 400);
		}


		$this->_classItem = 'entry';
		$pageAction = '';


		$postClass = Post_Model_ClassRegistry::getClassFromContainer($this->_classIdName);
		if ($postClass !== NULL) {
			$this->_classIdName = $postClass;
		}

		$this->_classItem = Post_Model_ClassRegistry::getClassEntry($this->_classIdName);
		$this->_classContainer = Post_Model_ClassRegistry::getClassContainer($this->_classIdName);
		if (empty($this->_classItem) || empty($this->_classContainer)) {
			throw new Zend_Controller_Action_Exception('Unexpected post class ['.__LINE__.']', 400);
		}


		$param1 = $this->_getParam('page_param1');
		if (stripos($param1, 'page-') === 0 || stripos($param1, 'offset-') === 0) {
			$pageAction = 'list';
		}
		if ($param1 === 'drafts' || $param1 === 'trash') {
			$pageAction = 'list';
		}


		if (empty($pageAction)) {
			$pageAction = $this->_getParam('post_action');
		}
		if (empty($pageAction)) {
			$postIdParam = $this->_getParam('post_id');
			if (stripos($postIdParam, $this->_classItem .'-') === 0) {
				$pageAction = 'view';
			}
		}
		if (empty($pageAction)) {
			if (stripos($param1, $this->_classItem .'-') === 0) {
				$pageAction = 'view';
			} else {
				$pageAction = $param1;
			}
		}

		if (empty($pageAction) === FALSE) {
			if ($pageAction === $this->_classItem) {
				$pageAction = 'view';
			} else {
				$pageAction = str_replace($this->_classItem, '', $pageAction);
			}
		}

		if (empty($pageAction) || $pageAction === 'index') {
			$pageAction = 'list';
		} else if ($pageAction === 'new') {
			$pageAction = 'edit';
		}

		if (empty($pageAction) === FALSE) {
			$this->_forward($pageAction);
		}
	}


	public function listAction()
	{
		$parentId = intval($this->_getParam('post_parent_id'));
		$sortMode = $this->_getParam('post_sort_mode');

		$loadContent = FALSE;

		$displayMode = $this->_getParam('widget_display_mode');

		switch ($this->_classIdName)
		{
		case 'wall':
			$loadContent = TRUE;
			switch ($displayMode) {
			case 'small': $postCount = 5; break;
			case 'large': $postCount = 10; break;
			case 'full':
			case 'single': $postCount = 20; break;
			}
			break;
		case 'note':
			switch ($displayMode) {
			case 'small': $postCount = 5; $loadContent = FALSE; break;
			case 'large': $postCount = 10; $loadContent = FALSE; break;
			case 'full': 
			case 'single': $postCount = 10; $loadContent = TRUE; break;
			}
			break;
		case 'forum':
			$loadContent = FALSE;
			switch ($displayMode) {
			case 'small': $postCount = 5; break;
			case 'large': $postCount = 10; break;
			case 'full': 
			case 'single': $postCount = 20; break;
			}
			break;
		case 'comment':
			$loadContent = TRUE;
			$postCount = 20;
			break;
		}

		$listSize = intval($this->_getParam('post_list_size'));
		if ($listSize > 1 && $listSize <= 100) {
			$postCount = $listSize;
		}

		$listStart = 0;
		$offsetRev = FALSE;
		$param1 = $this->_getParam('page_param1');
		if (empty($param1)) {
			$listStart = intval($this->_getParam('post_list_start'));
			if ($listStart < 0) {
				$offsetRev = TRUE;
				$listStart = -$listStart;
			}
		} else {
			if (stripos($param1, 'offset-') === 0) {
				$plist = explode('-', $param1, 2);
				$listStart = intval($plist[1]);
			} else if (stripos($param1, 'page-') === 0) {
				$plist = explode('-', $param1, 2);
				$listStart = (intval($plist[1]) - 1) * $postCount;
			}
		}

		//TODO: parse draft/spam/delete parameter
		$draftsView = $this->_getParam('page_param1') === 'drafts';


		$queryParams = array();

		$queryParams['count'] = $postCount;

		if ($sortMode === 'oldest') {
			$queryParams['oldest'] = TRUE;
		}
		if ($draftsView === TRUE) {
			$queryParams['draft'] = TRUE;
		}
		if ($this->_classIdName === 'forum') {
			$queryParams['latest_updates'] = TRUE;
		}

		if ($parentId > 0) {
			$queryParams['parent_id'] = $parentId;
		} else if ($this->_hostObj != NULL) {
			$queryParams['host_class'] = $this->_hostClassIdName;
			$queryParams['host_id'] = $this->_hostId;
		}

		$countTotal = Post_Model_Entry::countInstances($this->_classIdName, $queryParams);

		if ($listStart > 0) {
			if ($offsetRev) {
				if ($countTotal > $listStart) {
					$listStart = $countTotal - $listStart;
					$queryParams['start'] = $listStart;
				} else {
					$listStart = 0;
				}
			} else {
				$queryParams['start'] = $listStart;
			}
		}

		$instances = Post_Model_Entry::getInstances($this->_classIdName, $queryParams);


		$sessAcc = Account_Model_Session::getAccount();

		$posts = array();

		$nhParams = array('host_class' => 'post.'. $this->_classIdName);
		$pn = $listStart + 1;

		//TODO: iterate the wall entries and get the post instance for each entry and then prepare the data to be rendered
		foreach ($instances as $post) {

			$creator = Account_Model_Account::getInstanceById($post->getCreatorId());

			$p = new stdClass();

			$p->number = $pn;
			$pn++;

			$p->id = $post->getId();
			if ($this->_classIdName === 'wall' || $this->_classIdName === 'comment') {
				$p->url = site_url_base($this->_pathInfo . $post->getUrl());
			} else {
				$p->url = site_url_base($this->_pathInfo . $post->getUrl(array('slug'=>TRUE)));
			}
			$p->time = $post->getTime();
			$p->creatorUrl = site_url_base($creator->getUrl());
			$p->creatorName = $creator->getNicename();
			$p->title = $post->getTitle();
			$p->published = $post->getPublishFlag();

			if ($loadContent) {
				require_once 'exts/markdown.php';
				$p->content = Markdown($post->getContent());
			}

			$updaterId = $post->getUpdaterId();
			if (intval($updaterId) > 0) {
				$updater = Account_Model_Account::getInstanceById($updaterId);
				if ($updater) {
					$p->updateTime = $post->getUpdateTime();
					$p->updaterId = $post->getUpdaterId();
					$p->updaterUrl = site_url_base($updater->getUrl());
					$p->updaterName = $updater->getNicename();
				}
			}

			// If this list is accessed not from host route, show the url to the host
			if ($this->_hostObj === NULL) {
				$hostObj = Euso_Object::getInstance($post->getHostClassIdName(), $post->getHostId());
				if ($hostObj !== NULL) {
					$p->hostLinkVisible = TRUE;
					$p->hostUrl = site_url_base('/'. $post->getHostClassIdName() .'/'. $hostObj->getIdName()); //TODO: get this from the object
					$p->hostName = $hostObj->getNicename();
				}
			} else {
				$hostObj = $this->_hostObj;
			}

			if (Kernel::getInstance()->isModuleActive('profile')) {
				$p->creatorAvatarUrl = Profile_Model_Avatar::getFileUrl('user', $post->getCreatorId());
			} else {
				$p->creatorAvatarUrl = '';
			}

			if ($sessAcc != NULL
				&& $this->_classIdName !== 'wall'
				&& $this->_hostClassIdName !== 'post.wall'
				&& $this->_hostClassIdName !== 'post.note'
				&& (($post->getHostClassIdName() === 'user' && $post->getHostId() === $sessAcc->getId())
				|| ($post->getCreatorId() === $sessAcc->getId())
				|| ($hostObj != NULL
				&& $hostObj->userHasObjectAccess($sessAcc->getId(), $this->_classIdName, $post->getId(), 'UPDATE')))) {

				$p->editLinkUrl = site_url_base($post->getUrl(array('action'=>'edit')));

			} else {
				$p->editLinkUrl = NULL;
			}
			if ($sessAcc != NULL
				&& (($this->_hostClassIdName === 'user' && $sessAcc->getId() === $post->getHostId())
				|| ($post->getCreatorId() === $sessAcc->getId())
				|| ($hostObj != NULL
				&& $hostObj->userHasObjectAccess($sessAcc->getId(), $this->_classIdName, $post->getId(), 'DELETE')))) {

				$p->deleteLinkUrl = site_url_base($post->getUrl(array('action'=>'delete')));

			} else {
				$p->deleteLinkUrl = NULL;
			}

			$nhParams['host_id'] = $post->getId();
			$p->commentCount = Post_Model_Entry::countInstances('comment', $nhParams);

			$posts[] = $p;
		}


		$postLevel = intval($this->view->postListLevel) + 1;


		$viewVars = new stdClass();


		$viewVars->postList = $posts;

		$viewVars->postCount = is_array($posts) ? count($posts) : 0;
		$viewVars->postCountTotal = $countTotal;

		$viewVars->postListFirst = $listStart + 1;
		$viewVars->postListLast = $listStart + $viewVars->postCount;

		$baseNavUrl = $this->_getParam('post_base_nav_url');
		if ($viewVars->postListFirst > 1) {
			if (empty($baseNavUrl)) {
				$viewVars->postListPagePrevUrl = site_url_base($this->_pathInfo
					.'/'. $this->_classContainer);
			} else {
				$viewVars->postListPagePrevUrl = $baseNavUrl;
			}
			$listPrevStart = ($listStart - $postCount);
			if ($listPrevStart > 0) {
				$viewVars->postListPagePrevUrl .= '/offset-'. $listPrevStart;
			}
		}
		if ($viewVars->postListLast < $viewVars->postCountTotal) {
			if (empty($baseNavUrl)) {
				$viewVars->postListPageNextUrl = site_url_base($this->_pathInfo
					.'/'. $this->_classContainer .'/offset-'. $viewVars->postListLast);
			} else {
				$viewVars->postListPageNextUrl = $baseNavUrl .'/offset-'. $viewVars->postListLast;
			}
		}


		//TODO: authorization
		if ($sessAcc != NULL
			&& (($this->_hostClassIdName === 'user' && $sessAcc->getId() == $this->_hostId)
			|| ($this->_hostObj != NULL
			&& $this->_hostObj->userHasObjectAccess($sessAcc->getId(), $this->_classIdName, NULL, 'PUT')))) {

			$viewVars->adminToolsVisible = TRUE;

			$viewVars->publishedListUrl = site_url_base($this->_pathInfo .'/'. $this->_classContainer);
			$viewVars->draftListUrl = site_url_base($this->_pathInfo .'/'. $this->_classContainer .'/drafts');
			$viewVars->addLinkUrl = site_url_base($this->_pathInfo .'/'. $this->_classContainer .'/new'. $this->_classItem);

		} else {
			$viewVars->adminToolsVisible = FALSE;
		}

//		$viewVars->submitUrl = site_url_base('/'. $this->_classContainer .'/new');
		$viewVars->submitUrl = site_url_base('/'. $this->_classIdName .'/new');
		$viewVars->hostClassIdName = $this->_hostClassIdName;
		$viewVars->hostId = $this->_hostId;
		$viewVars->parentId = $parentId;

		$inlineFormVisible = intval($this->_getParam('post_form_inline')) === 1;
		if ($inlineFormVisible && $viewVars->adminToolsVisible) {
			$viewVars->submitTopFormVisible = $sortMode !== 'oldest';
			$viewVars->submitBottomFormVisible = !$viewVars->submitTopFormVisible;
		}


		if (is_array($this->view->postListVars) === FALSE) {
			$this->view->postListVars = array();
		}
		$this->view->postListVars[$postLevel] = $viewVars;

		if (intval($this->_getParam('post_sublist')) === 1) {
			$this->view->postSublist = TRUE;
		}

		$this->view->postListLevel = $postLevel;


		$this->renderScript($this->_classIdName .'-list.'. $this->viewSuffix);


		$this->view->postListLevel -= 1;

		if ($displayMode === 'single') {
		$this->view->singleWidgetPage = TRUE;
			switch ($this->_classIdName) {
			case 'note':
				Kernel::getInstance()->setHeadTitle('Notes');
				$this->view->singleWidgetPageTitle = 'Notes';
				break;
			case 'forum':
				Kernel::getInstance()->setHeadTitle('Forum Threads');
				$this->view->singleWidgetPageTitle = 'Forum Threads';
				break;
			}
		}
	}

	//TODO: check for cross class reference
	public function viewAction()
	{
		//TODO: check ownership

		$request = $this->getRequest();

		$postId = $this->getPostId();

		if ($postId < 1) {
			throw new Zend_Controller_Action_Exception('Bad request ['.__LINE__.']', 400);
		}

		$post = Post_Model_Entry::getInstanceById($postId);
		if ($post === NULL) {
			throw new Zend_Controller_Action_Exception('Object not found ['.__LINE__.']', 404);
		}

		if ($post->getDeleteFlag() === TRUE) {
			throw new Zend_Controller_Action_Exception('Deleted', 410);
		}
//		if ($post->getPublishFlag() === FALSE) {
//			throw new Zend_Controller_Action_Exception('Object not found', 404);
//		}


		$sessAcc = Account_Model_Session::getAccount();

		//TODO: CHECKS
		$creator = Account_Model_Account::getInstanceById($post->getCreatorId());

		$p = new stdClass();

		$p->id = $post->getId();
		$p->url = site_url_base($this->_pathInfo . $post->getUrl(array('slug'=>TRUE)));
		$p->time = $post->getTime();

		$p->title = $post->getTitle();
		$p->published = $post->getPublishFlag();

		$p->creatorUrl = site_url_base($creator->getUrl());
		$p->creatorName = $creator->getNicename();

		if (Kernel::getInstance()->isModuleActive('profile')) {
			$p->creatorAvatarUrl = Profile_Model_Avatar::getFileUrl('user', $post->getCreatorId());
		} else {
			$p->creatorAvatarUrl = '';
		}

		require_once 'exts/markdown.php';
		$p->content = Markdown($post->getContent());


		// If this item is accessed not from the host route, show url to the host
		if ($this->_hostObj === NULL) {
			$hostObj = Euso_Object::getInstance($post->getHostClassIdName(), $post->getHostId());
			if ($hostObj !== NULL) {
				$p->hostLinkVisible = TRUE;
				$p->hostUrl = site_url_base('/'. $post->getHostClassIdName() .'/'. $hostObj->getIdName()); //TODO: get this from the object
				$p->hostName = $hostObj->getNicename();
			}
		} else {
			$hostObj = $this->_hostObj;
		}

		//TODO: authorization
		if ($sessAcc != NULL
			&& $this->_classIdName !== 'wall'
			&& $this->_hostClassIdName !== 'post.wall'
			&& (($post->getHostClassIdName() === 'user' && $post->getHostId() === $sessAcc->getId())
			|| ($post->getCreatorId() === $sessAcc->getId())
			|| ($hostObj != NULL
			&& $hostObj->userHasObjectAccess($sessAcc->getId(), $this->_classIdName, $post->getId(), 'UPDATE')))) {

			$p->editLinkUrl = site_url_base($post->getUrl(array('action'=>'edit')));

		} else {
			$p->editLinkUrl = NULL;
		}
		if ($sessAcc != NULL
			&& (($this->_hostClassIdName === 'user' && $sessAcc->getId() === $post->getHostId())
			|| ($post->getCreatorId() === $sessAcc->getId())
			|| ($hostObj != NULL
			&& $hostObj->userHasObjectAccess($sessAcc->getId(), $this->_classIdName, $post->getId(), 'DELETE')))) {

			$p->deleteLinkUrl = site_url_base($post->getUrl(array('action'=>'delete')));

		} else {
			$p->deleteLinkUrl = NULL;
		}

		$this->view->postEntry = $p;


		$this->view->requestParams = $request->getParams();

		$this->view->hostClassIdName = $this->_hostClassIdName;
		$this->view->hostId = $this->_hostId;


		$listStart = 0;
		$param2 = $this->_getParam('page_param2');
		if (empty($param2) === FALSE) {
			if (stripos($param2, 'offset-') === 0) {
				$plist = explode('-', $param2, 2);
				$listStart = intval($plist[1]);
			} else if (stripos($param2, 'page-') === 0) {
				$plist = explode('-', $param2, 2);
				$listStart = (intval($plist[1]) - 1) * $postCount;
			}
		}
		if ($listStart > 0) {
			$this->view->commentOffset = $listStart;
		}


		$this->renderScript($this->_classIdName .'-view.'. $this->viewSuffix);


		Kernel::getInstance()->setHeadTitle('View Post');
		$this->view->singleWidgetPageTitle = 'View Post';

		$this->view->singleWidgetPage = TRUE;
	}

	public function editAction()
	{
		$request = $this->getRequest();

		//TODO: authority
		if (Account_Model_Session::hasValidSession() === FALSE) {
			throw new Zend_Controller_Action_Exception('Access forbidden', 403);
		}

		$sessAcc = Account_Model_Session::getAccount();

		$postId = $this->getPostId();

		$newPost = $postId < 1;

		//TODO: check authority


		// New post needs to know their host
		if ($newPost && (empty($this->_hostClassIdName) || $this->_hostId < 1)) {
			throw new Zend_Controller_Action_Exception('Bad request ['.__LINE__.']', 400);
		}

		if ($newPost) {
			if ($sessAcc != NULL
				&& (($this->_hostClassIdName === 'user' && $sessAcc->getId() == $this->_hostId)
				|| ($this->_hostObj != NULL
				&& $this->_hostObj->userHasObjectAccess($sessAcc->getId(), $this->_classIdName, NULL, 'PUT')))) {

			} else {
				throw new Zend_Controller_Action_Exception('Access forbidden', 403);
			}
		} else {
			$post = Post_Model_Entry::getInstanceById($postId);
			if ($post === NULL) {
				throw new Zend_Controller_Action_Exception('Post not found', 404);
			}

			if ($sessAcc != NULL
				&& $this->_classIdName !== 'wall'
				&& $this->_hostClassIdName !== 'post.wall'
				&& (($this->_hostClassIdName === 'user' && $sessAcc->getId() === $post->getHostId())
				|| ($post->getCreatorId() === $sessAcc->getId())
				|| ($this->_hostObj != NULL
				&& $this->_hostObj->userHasObjectAccess($sessAcc->getId(), $this->_classIdName, $post->getId(), 'UPDATE')))) {

			} else {
				throw new Zend_Controller_Action_Exception('Access forbidden', 403);
			}
		}

		$formName = 'Post_Form_'. ucfirst($this->_classIdName);
		$form = new $formName();
		$form->setAction(site_url_base($request->getPathInfo()) .'?post_action=edit');

		// Check to see if this action has been POST'ed to.
		if ($request->isPost()) {

			// Now check to see if the form submitted exists, and
			// if the values passed in are valid for this form.
			if ($form->isValid($request->getPost())) {

				$values = $form->getValues();


				if (empty($values['post_title'])) {
					//TODO: based on words
					$values['post_title'] = substr($values['post_content'], 0, 32);

					if ($form->getElement('post_title')) {
						$form->post_title->setValue($values['post_title']);
					}
				}


				if ($newPost) {
					$parentId = intval($this->_getParam('post_parent_id'));

					$post = new Post_Model_Entry();
					$post
						->setClassIdName($this->_classIdName)
						->setCreatorId($sessAcc->getId())
						->setHostClassIdName($this->_hostClassIdName)
						->setHostId($this->_hostId)
						->setParentId($parentId)
					;
				}

				//TODO: authorization: allow non-creator to edit if the permission is set
				if ($post->getCreatorId() !== $sessAcc->getId()) {
					throw new Zend_Controller_Action_Exception('Access forbidden', 403);
				}

				if ($newPost === FALSE) {
					$post->setEditorId($sessAcc->getId());
					$post->saveRevision($values['post_content']);
				}

				$post
					->setTitle($values['post_title'])
					->setContent($values['post_content'])
				;

				if (empty($values['post_save']) === FALSE) {
					$post->setPublishFlag(FALSE);
				} else {
					$post->setPublishFlag(TRUE);
				}

				$post->save(TRUE);


				if ($newPost && $this->_hostClassIdName === 'user' && $this->_hostId == $sessAcc->getId() 
					&& Kernel::getInstance()->isModuleActive('profile')) {

					$profile = Profile_Model_Data::getInstance('user', $sessAcc->getId());
					$profile->setData('status', $values['post_content'], TRUE);
				}


				$submitReturn = $request->getParam('post_submit_return');
				if (empty($submitReturn) && $newPost === FALSE) {
					$submitReturn = $_SERVER['HTTP_REFERER'];
				}

				if (empty($submitReturn)) {
					$this->_redirect($post->getUrl(array('slug'=>TRUE)));
				} else {
					$redirector = $this->_helper->getHelper('Redirector');
					$redirector->setPrependBase(FALSE)->gotoUrl($submitReturn);
				}

			}

			$submitReturn = $request->getParam('post_submit_return');
			if (empty($submitReturn)) {
				$submitReturn = $_SERVER['HTTP_REFERER'];
			}
			$form->post_submit_return->setValue($submitReturn);

		} else if ($newPost === FALSE) {

			if ($form->getElement('post_title')) {
				$form->post_title->setValue($post->getTitle());
			}
			$form->post_content->setValue($post->getContent());

			$submitReturn = $request->getParam('post_submit_return');
			if (empty($submitReturn)) {
				$submitReturn = $_SERVER['HTTP_REFERER'];
			}
			$form->post_submit_return->setValue($submitReturn);

		}


		$this->view->form = $form;

		if ($newPost) {
			Kernel::getInstance()->setHeadTitle('New Post');
			$this->view->singleWidgetPageTitle = 'New Post';
		} else {
			Kernel::getInstance()->setHeadTitle('Edit Post');
			$this->view->singleWidgetPageTitle = 'Edit Post';
		}

		$this->view->singleWidgetPage = TRUE;
	}

	public function deleteAction()
	{
		//TODO: authority
		if (Account_Model_Session::hasValidSession() === FALSE) {
			throw new Zend_Controller_Action_Exception('Access forbidden', 403);
		}

		$sessAcc = Account_Model_Session::getAccount();

		$postId = $this->getPostId();

		if ($postId < 1) {
			throw new Zend_Controller_Action_Exception('Bad request ['.__LINE__.']', 400);
		}

		$post = Post_Model_Entry::getInstanceById($postId);
		if ($post === NULL) {
			throw new Zend_Controller_Action_Exception('Post not found', 404);
		}


		//TODO: authorization: allow non-creator to edit if the permission is set

		if ($sessAcc != NULL
			&& (($this->_hostClassIdName === 'user' && $sessAcc->getId() === $post->getHostId())
			|| ($post->getCreatorId() === $sessAcc->getId())
			|| ($this->_hostObj != NULL
			&& $this->_hostObj->userHasObjectAccess($sessAcc->getId(), $this->_classIdName, $post->getId(), 'DELETE')))) {

			$post->setDeleteFlag(TRUE);
			$post->save();


		//	$this->_redirect($this->_pathInfo .'/'. $this->_classIdName);
			// Back to the referer
			$this->_redirect($_SERVER['HTTP_REFERER']);

		} else {
			throw new Zend_Controller_Action_Exception('Access forbidden', 403);
		}
	}


	public function getPostId()
	{
		$param1 = $this->_getParam('post_id');
		if (empty($param1)) {
			$param1 = $this->_getParam('page_param1');
		}
		if (stripos($param1, $this->_classItem .'-') === 0) {
			$plist = explode('-', $param1, 3);
			$plist = explode('_', $plist[1], 2);
			return base_convert($plist[0], 36, 10);
		}
		return 0;
	}

}
